
#ifndef FONT_H
#define FONT_H

#include <ft2build.h>
#include FT_FREETYPE_H

#include <glm/glm.hpp>
#include <string>
#include <locale>
#include <codecvt>

namespace CC
{

    #define FONTCACHEVALUE (50)
    struct Font
    {
        FT_Face face;
        FT_Library ft;

        std::string path = "";
        std::string name = "";

        Font() = default;
        Font(const Font &f) = default;
    };

    class Texture2D;
    struct Character
    {
        Texture2D *texture2D; // texture
        glm::ivec2 size;      // font size
        glm::ivec2 bearing;   // Offset value from baseline to the left/top of the glyph
        unsigned int advance; // The distance from the origin to the next glyph origin
        float appFontSize;
    };

    signed long GetCharacterIndex(std::string c);

    void ParseUnicode(std::string file);

    Character &LoadCharacter(const Font &font, std::string name, unsigned int fontSize);
    Character& GetCharacter(std::string name, unsigned int fontSize = FONTCACHEVALUE);

    Character &LoadCharacterW(const Font &font, wchar_t &char_code, unsigned int fontSize);
    Character& GetCharacterW(wchar_t &char_code, unsigned int fontSize = FONTCACHEVALUE);

    static std::string wstring_to_string(const std::wstring& wstr)
    {
        std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
        return converter.to_bytes(wstr);
    }

    static std::wstring string_to_wstring(const std::string& str)
    {
        std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
        return converter.from_bytes(str);
    }

}
#endif